package com.ctl.utils;

import org.reflections.Reflections;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class ClassUtil {    /**
 * 获取有上面有某个注解的类
 * @param basePackage
 * @param annotationClass
 * @return
 * @param <T>
 */
public static <T extends Annotation> List<String> findAnnotatedClasses(String basePackage, Class<T> annotationClass) {
    Set<Class<?>> classes = cn.hutool.core.util.ClassUtil.scanPackageByAnnotation(basePackage, annotationClass);
    System.out.println(classes);
    List<String> classNames = new ArrayList<>();
    Reflections reflections = new Reflections(basePackage);
    Set<Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(annotationClass);
    for (Class<?> clazz : annotatedClasses) {
        T annotation = clazz.getAnnotation(annotationClass);
        System.out.println("Found class: " + clazz.getName() +"\t\t"+annotation.toString());
        classNames.add(clazz.getName());
    }
    return classNames;
}
}
